﻿@using ChinaHCM.QA.Core.Model
@using ChinaHCM.QA.Site.Model
@model BBSView
@{
    string divClass = "QAManager";
    if (ViewBag.TopicType == BoardType.Discuss)
    {
        divClass = "DiscussManager";
    }
}
<div class="@divClass clearfix">
    <strong>帖子管理： </strong><span>
        @if (ViewBag.TopicType == BoardType.QA)
        {
            if (!ViewBag.HasAnswer)
            { 
            @Ajax.ActionLink("设置为正确答案", "SetAnswer", "BBS", new { bbsId = Model.BBSId },
             new AjaxOptions() { HttpMethod = "Post", OnSuccess = "SetAnswerSuccess", Confirm = "确认要将所选回复设置为正确答案么？" })
            }
            else
            { 
            @Ajax.ActionLink("修改为正确答案", "ChangeAnswer", "BBS", new { bbsId = Model.BBSId },
             new AjaxOptions() { HttpMethod = "Post", OnSuccess = "ChangeAnswerSuccess", Confirm = "确认要将所选回复修改设置为正确答案么？若已经回答过正确答案，则会删除原先答案回帖。" })
            }
        }
    </span><span>
        @if (Model.DisplayMode == Mode.Public)
        { 
            @Ajax.ActionLink("隐藏", "SetHidden", "BBS", new { bbsId = Model.BBSId },
             new AjaxOptions() { HttpMethod = "Post", OnSuccess = "SetHiddenSuccess", Confirm = "确认要隐藏该贴么？隐藏后除发帖人外其他人将无法看到回复内容。" },
             new { id = "Hidden" })
        }
        else
        {
            @Ajax.ActionLink("取消隐藏", "SetHidden", "BBS", new { bbsId = Model.BBSId },
             new AjaxOptions() { HttpMethod = "Post", OnSuccess = "CancelHiddenSuccess" },
             new { id = "Hidden" })
        }
    </span><span>
        @Ajax.ActionLink("删除", "Delete", "BBS", new { bbsId = Model.BBSId },
             new AjaxOptions() { HttpMethod = "Post", OnSuccess = "DeleteSuccess", Confirm = "确认要删除此贴么？一旦删除将无法回复。" })
    </span>
</div>
<script type="text/javascript">
    function SetHiddenSuccess(data) {
        if (data.Flag == "0") {
            ZENG.msgbox.show("隐藏成功", 4, 2000);
            $("#Hidden").html("取消隐藏").attr("data-ajax-success", "CancelHiddenSuccess").attr("data-ajax-confirm", "");
        }
    }

    function CancelHiddenSuccess(data) {
        if (data.Flag == "0") {
            ZENG.msgbox.show("取消隐藏成功", 4, 2000);
            $("#Hidden").html("隐藏").attr("data-ajax-success", "SetHiddenSuccess").attr("data-ajax-confirm", "确认要隐藏该贴么？隐藏后除发帖人外其他人将无法看到回复内容。");
        }
    }

    function DeleteSuccess(data) {
        if (data.Flag == "0") {
            ZENG.msgbox.show("删除成功", 4, 2000);
            location.reload();
        }
    }

    function SetAnswerSuccess(data) {
        if (data.Flag == "0") {
            ZENG.msgbox.show("答案设置成功", 4, 2000);
            location.reload();
        }
    }

    function ChangeAnswerSuccess(data) {
        if (data.Flag == "0") {
            ZENG.msgbox.show("修改设置答案成功", 4, 2000);
            location.reload();
        }
    }
</script>
